package com.sskj.lib.bean;

import com.sskj.lib.util.CoinUtil;
import com.sskj.lib.util.NumberUtil;

import java.io.Serializable;
import java.util.List;

public class WSFiveBean implements Serializable {


    /**
     * name : EOS/USDT
     * bids : [{"totalSize":"90.1274","price":"7.2726"},{"price":"7.2714","totalSize":"167.9623"},{"price":"7.2703","totalSize":"1517.5989"},{"totalSize":"259.5996","price":"7.2698"},{"totalSize":"18.4373","price":"7.2696"}]
     * code : EOS/USDT
     * timestamp : 1533128490
     * asks : [{"totalSize":"99.9766","price":"7.2802"},{"totalSize":"13.6686","price":"7.2805"},{"price":"7.2809","totalSize":"500"},{"totalSize":"183.2281","price":"7.2816"},{"totalSize":"140.153","price":"7.2819"}]
     */

    private String name;
    private String code;
    private List<FiveBean> bids;
    private List<FiveBean> asks;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        if (code == null) {
            return code;
        }
        return code.replace("_", "/").toUpperCase();
    }

    public void setCode(String code) {
        this.code = code;
    }


    public List<FiveBean> getBids() {
        if (bids != null) {
            for (int i = 0; i < bids.size(); i++) {
                bids.get(i).setCode(code);
            }
        }
        return bids;
    }

    public void setBids(List<FiveBean> bids) {
        this.bids = bids;
    }

    public List<FiveBean> getAsks() {
        if (asks != null) {
            for (int i = 0; i < asks.size(); i++) {
                asks.get(i).setCode(code);
            }
        }
        return asks;
    }

    public void setAsks(List<FiveBean> asks) {
        this.asks = asks;
    }

    public static class FiveBean implements Serializable {
        public FiveBean(String totalSize, String price) {
            this.totalSize = totalSize;
            this.price = price;
        }

        public FiveBean(String totalSize, String price, String code) {
            this.totalSize = totalSize;
            this.price = price;
            this.code = code;
        }

        private int percent = 0;

        public int getPercent() {
            return percent;
        }

        public void setPercent(int percent) {
            this.percent = percent;
        }

        public FiveBean() {
        }

        /**
         * totalSize : 90.1274
         * price : 7.2726
         */


        private String totalSize;
        private String price;
        private String code;

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getDoubleTotalSize() {
            return totalSize == null ? "0" : totalSize;
        }

        public String getTotalSize() {
//            return (totalSize == null || totalSize.equals("--")) ? null : NumberUtil.keepPankouNum( totalSize);
            return (totalSize == null || totalSize.equals("--")) ? null : code.toUpperCase().contains("DIG") ? NumberUtil.keep(totalSize,2) : NumberUtil.keep4(totalSize);
        }

        public void setTotalSize(String totalSize) {
            this.totalSize = totalSize;
        }

        public String getPrice() {
//            return "10.0000089";
            return price == null ? null : CoinUtil.keepCoinPrice(code, price);
        }

        public void setPrice(String price) {
            this.price = price;
        }

        @Override
        public String toString() {
            return "FiveBean{" +
                    "percent=" + percent +
                    ", totalSize='" + totalSize + '\'' +
                    ", price='" + price + '\'' +
                    ", code='" + code + '\'' +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "WSFiveBean{" +
                "name='" + name + '\'' +
                ", code='" + code + '\'' +
                ", bids=" + bids +
                ", asks=" + asks +
                '}';
    }
}